from haystack import indexes

from goods.models import SKU


# 定义索引类，生成索引数据
class SKUIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)

    def get_model(self):
        # 指定建立索引的模型类
        return SKU

    def index_queryset(self, using=None):
        # 过滤数据
        return self.get_model().objects.filter(is_launched=True)
